<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
// +----------------------------------------------------------------------
/**
 * Class DelOrderSoundRecording
 * Desc  定时清除行程录音
 * Create on 2025/4/27 9:37
 * Create by wangyafang
 */

namespace app\api\controller\wddj;


use app\common\controller\Api;

class RegularlyOrderSoundRecording extends Api
{
    protected $noNeedLogin = ['del'];
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * Desc 删除
     * Create on 2025/4/27 9:39
     * Create by wangyafang
     */
    public function del()
    {
        if(!$this->request->isGet()) {
            $this->error('请求类型错误');
        }
        $time = time();
        $delData = (new \app\api\model\wddj\OrderSoundRecording())
            ->where('expire_time','<',$time)
            ->select();
        if (!empty($delData)) {
            \think\Hook::add('upload_delete', function ($params) {
                if ($params['storage'] == 'local') {
                    $attachmentFile = ROOT_PATH . '/public' . $params['url'];
                    if (is_file($attachmentFile)) {
                        @unlink($attachmentFile);
                    }
                }
            });
            $attachmentlist = $delData;
            foreach ($attachmentlist as $attachment) {
                \think\Hook::listen("upload_delete", $attachment);
                $attachment->delete();
            }
        }
        $this->success('请求成功');
    }
}



 